<template>
  <div>
    <p class="title">活动列表</p>
    <div class="main">
      <div class="he">
        <div class="box1">
          <div>
            <span>活动类型：</span>
            <el-select v-model="value1" placeholder="全部" size="small">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>

          <div>
            <span>活动进度：</span>
            <el-select v-model="value2" placeholder="全部" size="small">
              <el-option
                v-for="item in options2"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
          <div>
            <span>活动价格：</span>
            <el-select v-model="value3" placeholder="全部" size="small">
              <el-option
                v-for="item in options3"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </div>
        </div>
        <div class="search">
          <div class="el-icon-search"></div>
          <el-input
            class="seainput"
            type="text"
            placeholder="搜索用户/动态标题"
            v-model="input"
            @keyup.enter.native="search"
            @blur="search"
          />
        </div>

        <div class="lstse">
          <span>状态：</span>
          <el-select v-model="value4" placeholder="全部" size="small">
            <el-option
              v-for="item in options4"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <el-button type="primary" @click="add">新建</el-button>
    </div>

    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      border
    >
      <el-table-column label="序号" type="index" align="center">
        <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
      </el-table-column>
      <el-table-column prop="atyId" label="活动编号" align="center">
      </el-table-column>
      <el-table-column
        prop="atyName"
        label="活动名称"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="atyType"
        label="活动类型"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column label="报名时间" show-overflow-tooltip align="center">
        <template slot-scope="scope"
          >{{ scope.row.enrollStartTime }}-{{
            scope.row.enrollEndTime
          }}</template
        >
      </el-table-column>
      <el-table-column label="活动时间" show-overflow-tooltip align="center">
        <template slot-scope="scope"
          >{{ scope.row.atyStartTime }}-{{ scope.row.atyEndTime }}</template
        >
      </el-table-column>
      <el-table-column
        prop="atyState"
        label="活动进度"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="atyPrice"
        label="活动价格"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="enrollNumber"
        align="center"
        label="参与人数"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="state"
        label="状态"
        align="center"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop=""
        label="操作"
        align="center"
        show-overflow-tooltip
        width="120"
      >
        <template slot-scope="scope">
          <el-link
            type="primary"
            @click="bj(scope.row)"
            v-if="scope.row.atyState !== '已结束'"
            >编辑</el-link
          >
          <el-link type="primary" @click="ck(scope.row)">查看</el-link>
          <template v-if="scope.row.atyState !== '已结束'">
            <el-link
              type="primary"
              v-if="scope.row.state == '已上架'"
              @click="down(scope.row)"
              >下架</el-link
            >
            <el-link type="primary" v-else @click="up(scope.row)">上架</el-link>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Page
      :total="total"
      :pageNumber.sync="pageNumber"
      :pageSize.sync="pageSize"
      @current-change="changeCurrentPage"
      @size-change="handleSizeChange"
    >
    </Page>
  </div>
</template>

<script>
import Page from "../../components/page.vue";
import apis from "../../apis/modules/activityList";
export default {
  components: {
    Page,
  },
  data() {
    return {
      currentPage: 1,
      tableData: [],
      options: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "线上活动",
        },
        {
          value: "2",
          label: "线下活动",
        },
      ],

      value1: "all",
      options2: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "预热中",
        },
        {
          value: "2",
          label: "报名中",
        },
        {
          value: "3",
          label: "进行中",
        },
        {
          value: "4",
          label: "已结束",
        },
      ],

      value2: "all",
      options3: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "付费",
        },
        {
          value: "2",
          label: "免费",
        },
      ],

      value3: "all",
      options4: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "已上架",
        },
        {
          value: "2",
          label: "未上架",
        },
      ],

      value4: "all",
      input: "",
      total: null,
      pageNumber: "1",
      pageSize: "10",
    };
  },
  mounted() {
    this.getLiveBroadcast({
      atyType: this.value1,
      atyState: this.value2,
      priceType: this.value3,
      state: this.value4,
      pageNumber: this.pageNumber,
      pageSize: this.pageSize,
    });
  },
  watch: {
    value1() {
      this.getLiveBroadcast({
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
    value2() {
      this.getLiveBroadcast({
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
    value3() {
      this.getLiveBroadcast({
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
    value4() {
      this.getLiveBroadcast({
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
  },

  methods: {
    //上架
    up(data) {
      console.log(data);
      const state = {
        atyId: data.atyId,
        state: "1",
      };
      this.updateActivityState(state, "上架");
   
    },
    //下架
    down(data) {
      const state = {
        atyId: data.atyId,
        state: "2",
      };
      this.updateActivityState(state, "下架");
    },
    //  //活动上下架
    async updateActivityState(data, up) {
      await apis.updateActivityState(data).then((res) => {
        console.log(res);
        if (res.code == "200") {
          this.$message({
            message: `${up}成功`,
            type: "success",
          });
        }
            this.getLiveBroadcast({
      atyType: this.value1,
      atyState: this.value2,
      priceType: this.value3,
      state: this.value4,
      pageNumber: this.pageNumber,
      pageSize: this.pageSize,
    });
      });
    },
    //活动详情
    async getLiveBroadcast(data) {
      apis.getLiveBroadcast(data).then((res) => {
        this.total = res.data.count;
        this.tableData = res.data.list;
        const list = this.tableData;
        list.map((res) => {
          switch (res.atyState) {
            case "1":
              res.atyState = "预热中";
              break;
            case "2":
              res.atyState = "报名中";
              break;
            case "3":
              res.atyState = "进行中";
              break;
            case "4":
              res.atyState = "已结束";
              break;

            default:
              break;
          }
          switch (res.atyType) {
            case "1":
              res.atyType = "线上活动";
              break;
            case "2":
              res.atyType = "线下活动";
              break;

            default:
              break;
          }
          switch (res.state) {
            case "1":
              res.state = "已上架";
              break;
            case "2":
              res.state = "未上架";
              break;

            default:
              break;
          }
          switch (res.atyPrice) {
            case 0:
              res.atyPrice = "免费";
              break;

            default:
              break;
          }
          return res;
        });
      });
    },
    //搜索
    search() {
      this.getLiveBroadcast({
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content: this.input,
      });
    },
    add() {
     this.$router.push({
        name: "AddActive",
        params: {
         list:[]
        },
      });
    },
    bj(data){
      console.log(data);
       this.$router.push({
        name: "AddActive",
        params: {
         list:data
        },
      });
    },
    ck(data) {
      this.$router.push({
        name: "ActiveDeail",
        params: {
          atyId: data.atyId,
          atyPrice: data.atyPrice,
        },
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    //分页
    changeCurrentPage(val) {
      this.pageNumber = val;
      const list = {
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content: this.input,
      };
      this.getLiveBroadcast(list);
      console.log(val, 333);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      const list = {
        atyType: this.value1,
        atyState: this.value2,
        priceType: this.value3,
        state: this.value4,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content: this.input,
      };

      this.getLiveBroadcast(list);
      console.log(val, 222);
    },
  
  },
};
</script>

<style lang="scss" scoped>
.title {
  margin-top: -10px;
  font-size: 14px;
}
.main {
  padding: 20px;
}
.el-input--small .el-input__inner {
  height: 32px;
  line-height: 32px;
  width: 126px;
}
.he {
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  .box1 {
    width: 800px;
    display: flex;
    justify-content: space-between;
    > div {
      display: flex;
      span {
        width: 100px;
        line-height: 30px;
      }
    }
  }
  .el-select {
    margin-right: 40px;
  }
}
.box2 {
  width: 240px;
  height: 32px;
  line-height: 32px;

  background: #ccc;
  display: flex;
  border-radius: 8px;
  input {
    width: 240px;
    height: 30px;
    border-style: none;
    outline: none;
    margin-left: 10px;
    background: #ccc;
    border-radius: 8px;
  }
}
.el-button--primary {
  margin-top: 24px;
  width: 88px;
  height: 30px;
  line-height: 5px;
  float: right;
  margin-bottom: 20px;
}
.lstse {
  width: 300px;
  display: flex;
  margin-top: 20px;
  .el-select {
    width: 152px;
  }
  span {
    width: 75px;
  }
}
.search {
  /deep/.el-input__inner {
    -webkit-appearance: none;
    background-color: #dcdfe6;
    background-image: none;
    border-radius: 8px;
    border: 1px solid #dcdfe6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
  }
  height: 40px;
  background: #dcdfe6;
  // margin-top: 30px;
  display: flex;
  border-radius: 8px;
  .el-icon-search {
    line-height: 40px;
    height: 40px;
  }
}
</style>